import {computed} from 'vue'
import {useData} from 'vitepress'
import {createGiteeUrl} from '../utils'

import type {Ref} from 'vue'

export const useSourceCode = (path: Ref<string>) => {
    const {theme} = useData()

    const demoUrl = computed(() => {
        const {
            repo,
            docsDir = 'docs',
            docsBranch = 'dev',
            docsRepo = repo,
        } = theme.value

        return createGiteeUrl(docsRepo, docsDir, docsBranch, path.value)
    })

    return demoUrl
}
